﻿@using System.Web.Optimization
@using WebHelpers.Mvc5.Enum
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>
        @if (!string.IsNullOrWhiteSpace(ViewBag.Title))
        {
            @ViewBag.Title@: -
        }
        EYWeb
    </title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
    @Styles.Render("~/Bundles/css")
    @RenderSection("css", required: false)
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini fixed ">
    <div class="wrapper" style="height: auto; min-height: 100%;">
        @Html.Partial("_Header")
        @Html.Partial("_Sidebar")

        <div class="content-wrapper">
            <section class="content-header">
                <h1>
                    @*@ViewBag.Title
                        <small>@ViewBag.Description</small>*@
                </h1>
            </section>

            <section class="content">
                @RenderBody()
            </section>
        </div>

        @Html.Partial("_ControlSidebar")
    </div>

    <script src="@RouteJs.RouteJsHandler.HandlerUrl"></script>
    <script src="@EnumHandler.HandlerUrl"></script>
    @Scripts.Render("~/Bundles/js")
    <script src="~/Content/js/plugins/cookie/jquery.cookie.js"></script>
    @RenderSection("ViewSpecificJavascript", required: false)
    <script type="text/javascript">

        $(function () {
            init();
        })
        function init() {
            $.ajax({
                url: "/Menu/GetMenu",
                type: "get",
                dataType: "json",
                async: true,
                success: function (data) {
                    GetLoadNav(eval(data));
                    activeMenu();
                }
            });
        }

        function GetLoadNav(data) {
            var _html = "";
            $.each(data, function (i) {
                var row = data[i];
                if (row.ParentId == "0") {
                    _html += '<li class="treeview">';
                    _html += '<a data-id="' + row.Id + '" href="#" ><i class="' + row.Icon + '"></i><span>&nbsp;&nbsp;' +
                        row.FullName + '</span><span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span></a>';
                    var childNodes = row.ChildNodes;
                    if (childNodes.length > 0) {
                        _html += '<ul class="treeview-menu">';
                        $.each(childNodes, function (i) {
                            var subrow = childNodes[i];
                            _html += '<li>';
                            _html += '<a  data-id="' + subrow.Id + '" href="' + subrow.UrlAddress + '" data-index="' + subrow.SortCode +
                                '" onclick="clickMenu(this)"> <i class="' + subrow.Icon + '"></i> ' + subrow.FullName + '</a>';
                            _html += '</li>';
                        });
                        _html += '</ul>';
                    }
                    _html += '</li>';
                }
            });
            $("#sidebar-menu").prepend(_html);

        }

        function clickMenu(a) {
            top.$.cookie('eyweb_currentmoduleid', $(a).attr('data-id'), { path: "/" });
        }

        function activeMenu() {
            var url = window.location.href;
            $("#sidebar-menu a").each(function () {
                var me = this.parentNode;
                var parent = me.parentNode.parentNode;
                if (url.indexOf($(this).attr('href')) > -1 && $(this).attr('href').length > 1) {
                    $(parent).addClass('active menu-open').siblings().removeClass("active menu-open");
                    $(me).addClass('active').siblings().removeClass("active");
                }
            });
        }
    </script>
    @RenderSection("scripts", required: false)
</body>
</html>